<template>
  <div ref="chartRef" :style="{ height, width }"></div>
</template>
<script lang="ts" setup>
import { Ref, ref, watch, onMounted } from 'vue';
import { useECharts } from '/@/hooks/web/useECharts';
import { basicProps } from './props';

const props = defineProps({
  width: {
    type: String as PropType<string>,
    default: '100%',
  },
  height: {
    type: String as PropType<string>,
    default: '640px',
  },
  dataArray: {
    type: Array as PropType<any>,
    default: [],
  },
});
const chartRef = ref<HTMLDivElement | null>(null);
const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
let xAxisData = []
let series1Data = []
let series2Data = []

watch(
  () => props.dataArray,
  () => {
    xAxisData = []; series1Data = []; series2Data = [];
    for (let i = 0; i < props.dataArray.length; i++) {
      let item = props.dataArray[i];
      let timeStr = item['queryTimeStr'];
      let ser1 = item['chkCnt'];
      let ser2 = item['chkCnt'];
      xAxisData.push(timeStr)
      series1Data.push(ser1)
      series2Data.push(ser2)
    }
    setOptions({
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          lineStyle: {
            width: 1,
            color: '#019680',
          },
        },
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: xAxisData,
        splitLine: {
          show: true,
          lineStyle: {
            width: 1,
            type: 'solid',
            color: 'rgba(226,226,226,0.5)',
          },
        },
        axisTick: {
          show: false,
        },
      },
      yAxis: [
        {
          minInterval: 1,
          type: 'value',
          splitNumber: 4,
          axisTick: {
            show: false,
          },
          splitArea: {
            show: true,
            areaStyle: {
              color: ['rgba(255,255,255,0.2)', 'rgba(226,226,226,0.2)'],
            },
          },
        },
      ],
      grid: { left: '1%', right: '1%', top: '2  %', bottom: 0, containLabel: true },
      series: [
        {
          name: '待完结单据',
          smooth: true,
          data: series1Data,
          type: 'line',
          areaStyle: {},
          itemStyle: {
            color: '#5ab1ef',
          },
        },
        {
          name: '已完结单据',
          smooth: true,
          data: series2Data,
          type: 'line',
          areaStyle: {},
          itemStyle: {
            color: '#019680',
          },
        },
      ],
    });
  },
  { immediate: true }
);

onMounted(() => {
  console.log('==VisitAnalysis==onMounted==>>', props.dataArray.length)
});
</script>
